package com.first.controller;

import com.first.dao.StatisticsDao;
import com.first.util.Echarts;
import com.first.util.EchartsDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("statistics")
public class StatisticsController {
    @Autowired
    private StatisticsDao statisticsDao;

    @RequestMapping("xl")
        public List<Echarts> getBooknameAndPrice(String start,String end){
            Echarts echarts = new Echarts();

            if (start!=null && end!=null ){
                List<Echarts> echarts2 = statisticsDao.querySales(echarts,start,end);
                return echarts2;
            }else {
                Date date = new Date();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
                String dateString = formatter.format(date);
                String startDate=dateString+"-01-01";
                String endDate=dateString+"-12-31";
                List<Echarts> echarts1 = statisticsDao.querySales(echarts, startDate, endDate);
                return echarts1;
            }

    }

    @RequestMapping("profit")
    public List<Echarts> getprofit(String start,String end){
        Echarts echarts = new Echarts();

        if (start!=null && end!=null ){
            List<Echarts> echarts2 = statisticsDao.queryProfit(echarts,start,end);
            return echarts2;
        }else {
            Date date = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
            String dateString = formatter.format(date);
            String startDate=dateString+"-01-01";
            String endDate=dateString+"-12-31";
            List<Echarts> echarts1 = statisticsDao.queryProfit(echarts, startDate, endDate);
            return echarts1;
        }

    }

    @RequestMapping("stock")
    public List<EchartsDate> getStock() {
        EchartsDate echarts = new EchartsDate();
        List<EchartsDate> stock = statisticsDao.getStock(echarts);
        System.out.println(stock);
        return stock;
    }






}
